<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JavaScript知识点总结(三.ECMAScript之变量和数据类型) | 小何blog (记录美好)</title><meta name="keywords" content="系列🏬,JavaScript,ECMAScript"><meta name="author" content="六根清静"><meta name="copyright" content="六根清静"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="ECMAScript是JavaScript的规格，JavaScript是ECMAScript的一种实现，在日常场合，这两个词是可以互换的。想要学习JavaScript，基础部分就是先学好JavaScript的核心语法部分ECMAScript。">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript知识点总结(三.ECMAScript之变量和数据类型)">
<meta property="og:url" content="https://liugenqingjing2.coding.me/2020/09/06/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%89-ECMAScript%E4%B9%8B%E5%8F%98%E9%87%8F%E5%92%8C%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html">
<meta property="og:site_name" content="小何blog (记录美好)">
<meta property="og:description" content="ECMAScript是JavaScript的规格，JavaScript是ECMAScript的一种实现，在日常场合，这两个词是可以互换的。想要学习JavaScript，基础部分就是先学好JavaScript的核心语法部分ECMAScript。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-a049026224c43dcadeabad571c8d0d27_r.jpg">
<meta property="article:published_time" content="2020-09-06T13:32:27.000Z">
<meta property="article:modified_time" content="2021-01-10T12:15:05.385Z">
<meta property="article:author" content="六根清静">
<meta property="article:tag" content="系列🏬">
<meta property="article:tag" content="JavaScript">
<meta property="article:tag" content="ECMAScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-a049026224c43dcadeabad571c8d0d27_r.jpg"><link rel="shortcut icon" href="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/wOu*ZmuVb5A4.png"><link rel="canonical" href="https://liugenqingjing2.coding.me/2020/09/06/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%89-ECMAScript%E4%B9%8B%E5%8F%98%E9%87%8F%E5%92%8C%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin="crossorigin"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e829919a4d931d733ee74d5d97a51582";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":20,"languages":{"author":"作者: 六根清静","link":"链接: ","source":"来源: 小何blog (记录美好)","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-01-10 20:15:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '2'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"><link rel="stylesheet" href="/css/shuo.css"/><link rel="stylesheet" href="/magnetcss/magnet.css"/><link rel="stylesheet" href="/css/calendar.css"/><link rel="stylesheet" href="//at.alicdn.com/t/font_2060620_l0j6b710zk.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/font-awesome-animation.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><link rel="stylesheet" href="/css/change.css"><link rel="stylesheet" href="/news/css/news.css"/><style type="text/css">#toggle-sidebar {bottom: 80px}</style><link rel="stylesheet" href="/magnet/css/catalogMagnet.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/iconfont.min.css"><link rel="stykesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/pool.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/><link rel="stylesheet" href="/zan/zan.css"><link rel="stylesheet" href="/swiper/swiper.min.css"><link rel="stylesheet" href="/swiper/swiperstyle.css"><style>#article-container.post-content h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { -webkit-animation: avatar_turn_around 1s linear infinite; -moz-animation: avatar_turn_around 1s linear infinite; -o-animation: avatar_turn_around 1s linear infinite; -ms-animation: avatar_turn_around 1s linear infinite; animation: avatar_turn_around 1s linear infinite; }</style><meta name="generator" content="Hexo 5.0.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-a049026224c43dcadeabad571c8d0d27_r.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小何blog (记录美好)</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">JavaScript知识点总结(三.ECMAScript之变量和数据类型)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-09-06T13:32:27.000Z" title="发表于 2020-09-06 21:32:27">2020-09-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-10T12:15:05.385Z" title="更新于 2021-01-10 20:15:05">2021-01-10</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF%E5%AD%A6%E4%B9%A0/">前端学习</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.9k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="变量："><a href="#变量：" class="headerlink" title="变量："></a>变量：</h1><blockquote>
<p>纯属随笔记录，具体详细教程，请查阅<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/">MDN Web 文档</a></p>
</blockquote>
<ol>
<li><h2 id="变量概述："><a href="#变量概述：" class="headerlink" title="变量概述："></a>变量概述：</h2><ul>
<li><h3 id="什么是变量"><a href="#什么是变量" class="headerlink" title="什么是变量:"></a>什么是变量:</h3><ul>
<li><strong>白话：</strong>变量就是一个装东西的盒子。</li>
<li><strong>通俗：</strong>变量是用于存放数据的容器。 我们通过 <strong>变量名</strong> 获取数据，甚至数据可以修改。</li>
</ul>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/gta1ja*cKXZi.png" alt="变量描述"></p>
</li>
<li><h3 id="变量在内存中的存储"><a href="#变量在内存中的存储" class="headerlink" title="变量在内存中的存储:"></a>变量在内存中的存储:</h3><ul>
<li><strong>本质：</strong>变量是程序在<strong>内存</strong>中申请的一块用来<strong>存放数据</strong>的空间。</li>
<li>类似我们酒店的房间，一个房间就可以看做是一个变量。</li>
</ul>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/ep6NprKyJMkR.png" alt="变量在内存中的存储"></p>
</li>
</ul>
</li>
<li><h2 id="变量的使用"><a href="#变量的使用" class="headerlink" title="变量的使用:"></a>变量的使用:</h2><blockquote>
<p>变量在使用时分为两步： 1. 声明变量   2. 赋值</p>
</blockquote>
<ul>
<li><h3 id="声明变量"><a href="#声明变量" class="headerlink" title="声明变量:"></a>声明变量:</h3></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//  声明变量  </span></span><br><span class="line"><span class="keyword">var</span> age;     <span class="comment">//  声明一个 名称为age 的变量</span></span><br></pre></td></tr></table></figure>

<h4 id="注"><a href="#注" class="headerlink" title="注:"></a>注:</h4><ol>
<li><code>var</code> 是一个 <strong>JS关键字</strong>，用来声明变量( variable 变量的意思 )。使用该关键字声明变量后，<strong>计算机会自动为变量分配内存空间</strong>，不需要程序员管</li>
<li><code>age</code> 是程序员定义的<strong>变量名</strong>，我们要通过变量名来访问内存中分配的空间</li>
</ol>
<hr>
</li>
</ol>
<ul>
<li><h3 id="赋值"><a href="#赋值" class="headerlink" title="赋值:"></a>赋值:</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">age = <span class="number">10</span>;     <span class="comment">// 给 age 这个变量赋值为 10</span></span><br></pre></td></tr></table></figure>

<h4 id="注-1"><a href="#注-1" class="headerlink" title="注:"></a>注:</h4></li>
</ul>
<ol>
<li><code>= </code> 用来把<strong>右边的值赋给左边</strong>的变量空间中   此处代表<strong>赋值</strong>的意思</li>
<li><strong>变量值</strong>是程序员保存到变量空间里的值</li>
</ol>
<hr>
<ul>
<li><h3 id="变量的初始化"><a href="#变量的初始化" class="headerlink" title="变量的初始化:"></a>变量的初始化:</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> age  = <span class="number">18</span>;  <span class="comment">// 声明变量同时赋值为 18</span></span><br></pre></td></tr></table></figure>

<h4 id="注-2"><a href="#注-2" class="headerlink" title="注:"></a>注:</h4></li>
</ul>
<ol>
<li>声明一个变量并赋值， 我们称之为变量的<strong>初始化</strong>。</li>
</ol>
<ol start="3">
<li><h2 id="变量语法扩展"><a href="#变量语法扩展" class="headerlink" title="变量语法扩展:"></a>变量语法扩展:</h2><ul>
<li><h3 id="更新变量"><a href="#更新变量" class="headerlink" title="更新变量:"></a>更新变量:</h3><ul>
<li>一个变量被<strong>重新复赋值</strong>后，它原有的值就会被<strong>覆盖</strong>，变量值将以最后一次赋的值为准。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">18</span>;</span><br><span class="line"></span><br><span class="line">age = <span class="number">81</span>;   <span class="comment">// 最后的结果就是81因为18 被覆盖掉了 </span></span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="同时声明多个变量"><a href="#同时声明多个变量" class="headerlink" title="同时声明多个变量:"></a>同时声明多个变量:</h3><ul>
<li>同时声明多个变量时，只需要写<strong>一个 var</strong>， 多个变量名之间使用<strong>英文逗号</strong>隔开。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">10</span>,  name = <span class="string">&#x27;zs&#x27;</span>, sex = <span class="number">2</span>;</span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="声明变量特殊情况"><a href="#声明变量特殊情况" class="headerlink" title="声明变量特殊情况:"></a>声明变量特殊情况:</h3><table>
<thead>
<tr>
<th align="center">情况</th>
<th align="center">说明</th>
<th align="center">结果</th>
</tr>
</thead>
<tbody><tr>
<td align="center">var  age ; console.log (age);</td>
<td align="center">只声明 不赋值</td>
<td align="center">undefined</td>
</tr>
<tr>
<td align="center">console.log(age)</td>
<td align="center">不声明 不赋值  直接使用</td>
<td align="center">报错</td>
</tr>
<tr>
<td align="center">age   = 10; console.log (age);</td>
<td align="center">不声明 只赋值</td>
<td align="center">10</td>
</tr>
</tbody></table>
<h4 id="注-3"><a href="#注-3" class="headerlink" title="注:"></a>注:</h4><ul>
<li>最完美的写法就是<strong>即声明也赋值</strong>，因为不声明直接赋值，会成为<strong>全局变量</strong>的。</li>
</ul>
</li>
</ul>
</li>
<li><h2 id="变量命名规范"><a href="#变量命名规范" class="headerlink" title="变量命名规范:"></a>变量命名规范:</h2><ul>
<li><p><strong>由字母(A-Za-z)、数字(0-9)、下划线(_)、美元符号( $ )组成</strong>，如：usrAge, num01, _name</p>
</li>
<li><p><strong>严格区分大小写</strong>。var app; 和 var App; 是两个变量</p>
</li>
<li><p><strong>不能 以数字开头</strong>。  18age   是错误的</p>
</li>
<li><p><strong>不能 是关键字、保留字</strong>。例如：var、for、while</p>
</li>
<li><p><strong>变量名必须有意义</strong>。 MMD   BBD        nl   →     age </p>
</li>
<li><p><strong>遵守驼峰命名法</strong>。首字母小写，后面单词的首字母需要大写。 myFirstName</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/HT9wZtse7JbN.png" alt="驼峰"></p>
</li>
</ul>
<hr>
<h1 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h1></li>
<li><h2 id="数据类型简介："><a href="#数据类型简介：" class="headerlink" title="数据类型简介："></a>数据类型简介：</h2><ul>
<li><h3 id="为什么需要数据类型："><a href="#为什么需要数据类型：" class="headerlink" title="为什么需要数据类型："></a>为什么需要数据类型：</h3><ul>
<li>在计算机中，不同的数据所需占用的<strong>存储空间</strong>是不同的，为了便于把数据分成所需内存大小不同的数据，充分利用存储空间，于是定义了不同的数据类型。</li>
<li>简单来说，<strong>数据类型就是数据的类别型号</strong>。比如姓名“张三”，年龄18，这些数据的类型是不一样的。</li>
</ul>
</li>
<li><h3 id="变量的数据类型："><a href="#变量的数据类型：" class="headerlink" title="变量的数据类型："></a>变量的数据类型：</h3><ul>
<li>变量是用来<strong>存储值的所在处</strong>，它们有<strong>名字</strong>和<strong>数据类型</strong>。变量的数据类型决定了如何将代表这些值的位存储到计算机的内存中。<strong>JavaScript 是一种弱类型或者说动态语言</strong>。这意味着不用提前声明变量的类型，在程序运行过程中，<strong>类型会被自动确定</strong>。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">10</span>;        <span class="comment">// 这是一个数字型</span></span><br><span class="line"><span class="keyword">var</span> areYouOk = <span class="string">&#x27;是的&#x27;</span>;   <span class="comment">// 这是一个字符串  </span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>在代码运行时，变量的<strong>数据类型是由 JS引擎 根据 = 右边变量值的数据类型来判断的</strong>，运行完毕之后， 变量就确定了数据类型。</p>
<blockquote>
<p>JavaScript 拥有动态类型，同时也意味着相同的变量可用作不同的类型：</p>
</blockquote>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> x = <span class="number">6</span>;           <span class="comment">// x 为数字</span></span><br><span class="line"><span class="keyword">var</span> x = <span class="string">&quot;Bill&quot;</span>;      <span class="comment">// x 为字符串</span></span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="数据类型的分类"><a href="#数据类型的分类" class="headerlink" title="数据类型的分类:"></a>数据类型的分类:</h3><h4 id="JS-把数据类型分为两类"><a href="#JS-把数据类型分为两类" class="headerlink" title="JS 把数据类型分为两类:"></a>JS 把数据类型分为两类:</h4><ul>
<li><strong>简单数据类型 （Number,String,Boolean,Undefined,Null）</strong></li>
<li>**复杂数据类型 （object)    **</li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="简单数据类型："><a href="#简单数据类型：" class="headerlink" title="简单数据类型："></a>简单数据类型：</h2><ul>
<li><h3 id="简单数据类型（基本数据类型）"><a href="#简单数据类型（基本数据类型）" class="headerlink" title="简单数据类型（基本数据类型）:"></a>简单数据类型（基本数据类型）:</h3><table>
<thead>
<tr>
<th align="center">简单数据类型</th>
<th align="center">说明</th>
<th align="center">默认值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">Number</td>
<td align="center">数字型，包含整型值和浮点型值，如21、0.21</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">Boolean</td>
<td align="center">布尔值类型，如true .false，等价于1和О</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">String</td>
<td align="center">字符串类型，如”张三”注意咱们js里面，字符串都带引号</td>
<td align="center">“”</td>
</tr>
<tr>
<td align="center">Undefined</td>
<td align="center">var a;声明了变量a但是没有给值，此时a = undefined</td>
<td align="center">undefined</td>
</tr>
<tr>
<td align="center">Null</td>
<td align="center">var a = null;声明了变量a为空值</td>
<td align="center">null</td>
</tr>
</tbody></table>
</li>
<li><h3 id="数字型-Number："><a href="#数字型-Number：" class="headerlink" title="数字型 Number："></a>数字型 Number：</h3><ul>
<li><p>JavaScript 数字类型既可以用来保存<strong>整数值</strong>，也可以保存<strong>小数(浮点数）</strong>。</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">21</span>;       <span class="comment">// 整数</span></span><br><span class="line"><span class="keyword">var</span> Age = <span class="number">21.3747</span>;  <span class="comment">// 小数 </span></span><br></pre></td></tr></table></figure>
</li>
<li><h4 id="数字型进制"><a href="#数字型进制" class="headerlink" title="数字型进制:"></a>数字型进制:</h4><blockquote>
<p>最常见的进制有二进制、八进制、十进制、十六进制。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 1.八进制数字序列范围：0~7</span></span><br><span class="line"><span class="keyword">var</span> num1 = <span class="number">07</span>;   <span class="comment">// 对应十进制的7</span></span><br><span class="line"><span class="keyword">var</span> num2 = <span class="number">019</span>;  <span class="comment">// 对应十进制的19</span></span><br><span class="line"><span class="keyword">var</span> num3 = <span class="number">08</span>;   <span class="comment">// 对应十进制的8</span></span><br><span class="line"><span class="comment">// 2.十六进制数字序列范围：0~9以及A~F</span></span><br><span class="line"><span class="keyword">var</span> num = <span class="number">0xA</span>;   </span><br></pre></td></tr></table></figure>
</li>
<li><p>现阶段我们只需要记住，<strong>在JS中八进制前面加0，十六进制前面加 0x</strong></p>
</li>
</ul>
<hr>
<ul>
<li><h4 id="数字型范围"><a href="#数字型范围" class="headerlink" title="数字型范围:"></a>数字型范围:</h4><blockquote>
<p>JavaScript中数值的最大和最小值</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">alert(<span class="built_in">Number</span>.MAX_VALUE); <span class="comment">// 1.7976931348623157e+308</span></span><br><span class="line">alert(<span class="built_in">Number</span>.MIN_VALUE); <span class="comment">// 5e-324</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>最大值：</strong><code>Number.MAX_VALUE</code>，这个值为： 1.7976931348623157e+308</p>
</li>
<li><p>**最小值：<code>**Number.MIN_VALUE</code>，这个值为：5e-32</p>
</li>
</ul>
<hr>
<ul>
<li><h4 id="数字型三个特殊值"><a href="#数字型三个特殊值" class="headerlink" title="数字型三个特殊值:"></a>数字型三个特殊值:</h4></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">alert(<span class="literal">Infinity</span>);  <span class="comment">// Infinity</span></span><br><span class="line">alert(-<span class="literal">Infinity</span>); <span class="comment">// -Infinity</span></span><br><span class="line">alert(<span class="literal">NaN</span>);       <span class="comment">// NaN</span></span><br></pre></td></tr></table></figure>

<ul>
<li><code>Infinity</code> : <strong>代表无穷大，大于任何数值</strong></li>
<li><code>-Infinity</code> : <strong>代表无穷小，小于任何数值</strong></li>
<li><code>NaN</code> : <strong>Not a number，代表一个非数值</strong></li>
</ul>
<hr>
<ul>
<li><h4 id="isNaN"><a href="#isNaN" class="headerlink" title="isNaN():"></a>isNaN():</h4><p>用来判断一个变量<strong>是否为非数字的类型</strong>，返回 true 或者 false</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200908/nEc@@56DwHT0.png" alt="isNaN()示意图"></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">  <span class="keyword">var</span> usrAge = <span class="number">21</span>;</span><br><span class="line"><span class="keyword">var</span> isOk = <span class="built_in">isNaN</span>(userAge);</span><br><span class="line">   <span class="built_in">console</span>.log(isNum);            <span class="comment">// false ，21 不是一个非数字</span></span><br><span class="line"><span class="keyword">var</span> usrName = <span class="string">&quot;andy&quot;</span>;</span><br><span class="line">   <span class="built_in">console</span>.log(<span class="built_in">isNaN</span>(userName));  <span class="comment">// true ，&quot;andy&quot;是一个非数字</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
<hr>
<ul>
<li><h3 id="字符串型-String"><a href="#字符串型-String" class="headerlink" title="字符串型 String:"></a>字符串型 String:</h3><p>字符串型可以是引号中的任意文本，其语法为 **双引号 “” 和 单引号’’ **</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> strMsg = <span class="string">&quot;我爱北京天安门~&quot;</span>;  <span class="comment">// 使用双引号表示字符串</span></span><br><span class="line"><span class="keyword">var</span> strMsg2 = <span class="string">&#x27;我爱吃猪蹄~&#x27;</span>;    <span class="comment">// 使用单引号表示字符串</span></span><br><span class="line"><span class="comment">// 常见错误</span></span><br><span class="line"><span class="keyword">var</span> strMsg3 = 我爱大肘子;       <span class="comment">// 报错，没使用引号，会被认为是js代码，但js没有这些语法</span></span><br></pre></td></tr></table></figure>

<ul>
<li>因为 <strong>HTML 标签里面的属性使用的是双引号</strong>，<strong>JS 这里我们更推荐使用单引号。</strong></li>
</ul>
<hr>
<ul>
<li><h4 id="字符串引号嵌套"><a href="#字符串引号嵌套" class="headerlink" title="字符串引号嵌套:"></a>字符串引号嵌套:</h4><p>JS 可以用<strong>单引号嵌套双引号</strong> ，或者用<strong>双引号嵌套单引号 (外双内单，外单内双)</strong></p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> strMsg = <span class="string">&#x27;我是&quot;高帅富&quot;程序猿&#x27;</span>;   <span class="comment">// 可以用&#x27;&#x27;包含&quot;&quot;</span></span><br><span class="line"><span class="keyword">var</span> strMsg2 = <span class="string">&quot;我是&#x27;高帅富&#x27;程序猿&quot;</span>;  <span class="comment">// 也可以用&quot;&quot; 包含&#x27;&#x27;</span></span><br><span class="line"><span class="comment">//  常见错误</span></span><br><span class="line"><span class="keyword">var</span> badQuotes = <span class="string">&#x27;What on earth?&quot;; // 报错，不能 单双引号搭配</span></span><br></pre></td></tr></table></figure>

<ul>
<li><h4 id="字符串转义符"><a href="#字符串转义符" class="headerlink" title="字符串转义符:"></a>字符串转义符:</h4><p>类似HTML里面的特殊字符，字符串中也有<strong>特殊字符</strong>，我们称之为<strong>转义符</strong>。<br>转义符都是 <code>\ </code>开头的，常用的转义符及其说明如下：</p>
</li>
</ul>
<table>
<thead>
<tr>
<th align="center">转义符</th>
<th align="center">解释说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">\n</td>
<td align="center">换行符，n 是 newline 的意思</td>
</tr>
<tr>
<td align="center">\ \</td>
<td align="center">斜杠 \</td>
</tr>
<tr>
<td align="center">\‘</td>
<td align="center">‘   单引号</td>
</tr>
<tr>
<td align="center">\\“</td>
<td align="center">” 双引号</td>
</tr>
<tr>
<td align="center">\t</td>
<td align="center">tab  缩进</td>
</tr>
<tr>
<td align="center">\b</td>
<td align="center">空格 ，b 是 blank  的意思</td>
</tr>
</tbody></table>
<hr>
<ul>
<li><h4 id="字符串长度"><a href="#字符串长度" class="headerlink" title="字符串长度:"></a>字符串长度:</h4><p>字符串是由若干字符组成的，这些字符的数量就是字符串的长度。通过字符串的 <code>length</code> 属性可以<strong>获取整个字符串的长度。</strong></p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> strMsg = <span class="string">&quot;我是帅气多金的程序猿！&quot;</span>;</span><br><span class="line">alert(strMsg.length); <span class="comment">// 显示 11</span></span><br></pre></td></tr></table></figure>

<hr>
<ul>
<li><h4 id="字符串拼接"><a href="#字符串拼接" class="headerlink" title="字符串拼接:"></a>字符串拼接:</h4><ul>
<li>多个字符串之间可以使用<code>+</code>进行拼接，其拼接方式为 <strong>字符串 + 任何类型 = 拼接之后的新字符串</strong></li>
<li>拼接前会把与字符串相加的<strong>任何类型转成字符串</strong>，再拼接成一个新的字符串</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//1.1 字符串 &quot;相加&quot;</span></span><br><span class="line">alert(<span class="string">&#x27;hello&#x27;</span> + <span class="string">&#x27; &#x27;</span> + <span class="string">&#x27;world&#x27;</span>); <span class="comment">// hello world</span></span><br><span class="line"><span class="comment">//1.2 数值字符串 &quot;相加&quot;</span></span><br><span class="line">alert(<span class="string">&#x27;100&#x27;</span> + <span class="string">&#x27;100&#x27;</span>); <span class="comment">// 100100</span></span><br><span class="line"><span class="comment">//1.3 数值字符串 + 数值</span></span><br><span class="line">alert(<span class="string">&#x27;11&#x27;</span> + <span class="number">12</span>);     <span class="comment">// 1112 </span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>号总结口诀：数值相加 ，字符相连</p>
</blockquote>
<hr>
<ul>
<li><h4 id="字符串拼接加强"><a href="#字符串拼接加强" class="headerlink" title="字符串拼接加强:"></a>字符串拼接加强:</h4></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;老师&#x27;</span> + <span class="number">18</span>);           <span class="comment">// 只要有字符就会相连 </span></span><br><span class="line"><span class="keyword">var</span> age = <span class="number">18</span>;</span><br><span class="line"><span class="comment">// console.log(&#x27;老师age岁啦&#x27;);       // 这样不行哦</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;老师&#x27;</span> + age);          <span class="comment">// 老师18</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;老师&#x27;</span> + age + <span class="string">&#x27;岁啦&#x27;</span>);  <span class="comment">// 老师18岁啦</span></span><br></pre></td></tr></table></figure>

<ol>
<li>我们经常会将<strong>字符串和变量</strong>来拼接，因为变量可以很方便地修改里面的值</li>
<li>变量是不能添加引号的，因为<strong>加引号的变量会变成字符串</strong></li>
<li>如果变量两侧都有字符串拼接，口诀<strong>“引引加加 ”</strong>，删掉数字，变量写加中间</li>
</ol>
</li>
</ul>
<hr>
<ul>
<li><h3 id="布尔型-Boolean"><a href="#布尔型-Boolean" class="headerlink" title="布尔型 Boolean:"></a>布尔型 Boolean:</h3><p><strong>布尔类型有两个值：</strong><code>true 和 false </code>，其中 true 表示真（对），而 false 表示假（错）。<br><strong>布尔型和数字型相加的时候， true 的值为 1 ，false 的值为 0。</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="literal">true</span> + <span class="number">1</span>);  <span class="comment">// 2</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="literal">false</span> + <span class="number">1</span>); <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>

<hr>
<ul>
<li><h3 id="Undefined-和-Null"><a href="#Undefined-和-Null" class="headerlink" title="Undefined 和 Null:"></a>Undefined 和 Null:</h3></li>
</ul>
<p>​    一个声明后没有被赋值的变量会有一个默认值 <code>undefined</code> <strong>( 如果进行相连或者相加时，注意结果）</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> variable;</span><br><span class="line"><span class="built_in">console</span>.log(variable);           <span class="comment">// undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;你好&#x27;</span> + variable);  <span class="comment">// 你好undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="number">11</span> + variable);     <span class="comment">// NaN</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="literal">true</span> + variable);   <span class="comment">//  NaN</span></span><br></pre></td></tr></table></figure>

<p>​    一个声明变量给 <code>null</code> 值，<strong>里面存的值为空</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> vari = <span class="literal">null</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;你好&#x27;</span> + vari);  <span class="comment">// 你好null</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="number">11</span> + vari);     <span class="comment">// 11</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="literal">true</span> + vari);   <span class="comment">//  1</span></span><br></pre></td></tr></table></figure>

<hr>
</li>
</ul>
</li>
<li><h2 id="获取变量数据类型"><a href="#获取变量数据类型" class="headerlink" title="获取变量数据类型:"></a>获取变量数据类型:</h2><ul>
<li><h3 id="获取检测变量的数据类型"><a href="#获取检测变量的数据类型" class="headerlink" title="获取检测变量的数据类型:"></a>获取检测变量的数据类型:</h3><ul>
<li><code>typeof</code> 可用来获取检测<strong>变量的数据类型</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> num = <span class="number">18</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> num) <span class="comment">// 结果 number</span></span><br></pre></td></tr></table></figure>

<ul>
<li>不同类型的返回值:</li>
</ul>
<table>
<thead>
<tr>
<th align="center">类型</th>
<th align="center">例</th>
<th align="center">结果</th>
</tr>
</thead>
<tbody><tr>
<td align="center">String</td>
<td align="center">typeof ”小白”</td>
<td align="center">“string”</td>
</tr>
<tr>
<td align="center">Number</td>
<td align="center">typeof 18</td>
<td align="center">“number”</td>
</tr>
<tr>
<td align="center">Boolean</td>
<td align="center">typeof true</td>
<td align="center">“boolean”</td>
</tr>
<tr>
<td align="center">Undefined</td>
<td align="center">typeof undefined</td>
<td align="center">“undefined”</td>
</tr>
<tr>
<td align="center">Null</td>
<td align="center">typeof null</td>
<td align="center">“object”</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="字面量"><a href="#字面量" class="headerlink" title="字面量:"></a>字面量:</h3><p>字面量是在源代码中一个固定值的表示法，通俗来说，就是<strong>字面量表示如何表达这个值</strong>。</p>
<ul>
<li><strong>数字字面量：</strong>8, 9, 10</li>
<li><strong>字符串字面量：</strong>‘程序员’, “大前端”</li>
<li><strong>布尔字面量：</strong>true，false</li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="数据类型转换"><a href="#数据类型转换" class="headerlink" title="数据类型转换:"></a>数据类型转换:</h2><ul>
<li><h3 id="什么是数据类型转换"><a href="#什么是数据类型转换" class="headerlink" title="什么是数据类型转换:"></a>什么是数据类型转换:</h3><p>使用<strong>表单、<code>prompt </code>获取过来的数据默认是字符串类型的</strong>，此时就不能直接简单的进行加法运算，而需要转换变量的数据类型。通俗来说，<strong>就是把一种数据类型的变量转换成另外一种数据类型。</strong></p>
<blockquote>
<p>我们通常会实现3种方式的转换</p>
</blockquote>
<ol>
<li><strong>转换为字符串类型</strong></li>
<li><strong>转换为数字型</strong></li>
<li><strong>转换为布尔型</strong></li>
</ol>
<hr>
</li>
<li><h3 id="转换为字符串"><a href="#转换为字符串" class="headerlink" title="转换为字符串:"></a>转换为字符串:</h3><table>
<thead>
<tr>
<th align="center">方式</th>
<th align="center">说明</th>
<th align="center">案例</th>
</tr>
</thead>
<tbody><tr>
<td align="center">toString()</td>
<td align="center">转成字符串</td>
<td align="center">var name = 1; alert(num.toString())</td>
</tr>
<tr>
<td align="center">String()强制转换</td>
<td align="center">转成字符串</td>
<td align="center">var num= 1;alert(String(num))</td>
</tr>
<tr>
<td align="center">加号拼接字符串</td>
<td align="center">和字符串拼接的结果都是字符串</td>
<td align="center">var num = 1;alert(num + “我是字符串”)</td>
</tr>
</tbody></table>
<ul>
<li><code>toString()</code> 和 <code>String()</code>  使用方式不一样。</li>
<li>三种转换方式，我们更喜欢用<strong>第三种加号拼接字符串转换方式</strong>， 这一种方式也称之为<strong>隐式转换</strong>。</li>
</ul>
<hr>
</li>
<li><h3 id="转换为数字型（重点）"><a href="#转换为数字型（重点）" class="headerlink" title="转换为数字型（重点）:"></a>转换为数字型（重点）:</h3><table>
<thead>
<tr>
<th align="center">方式</th>
<th align="center">说明</th>
<th align="center">案例</th>
</tr>
</thead>
<tbody><tr>
<td align="center">parseInt(string) 函数</td>
<td align="center">将string类型转成整数数值型</td>
<td align="center">parseInt(‘78’)</td>
</tr>
<tr>
<td align="center">parseFloat(string)函数</td>
<td align="center">将string类型转成浮点数数值型</td>
<td align="center">parseFloat(‘78.21’)</td>
</tr>
<tr>
<td align="center">Number(string)强制转换函数</td>
<td align="center">将string类型转换为数值型</td>
<td align="center">Number(“12’)</td>
</tr>
<tr>
<td align="center">js隐式转换(- */ )</td>
<td align="center">利用算术运算隐式转换为数值型</td>
<td align="center">‘12’-o</td>
</tr>
</tbody></table>
<ul>
<li>注意 <code>parseInt</code> 和 <code>parseFloat</code> <strong>单词的大小写</strong>，这2个是重点</li>
<li><strong>隐式转换</strong>是我们在进行算数运算的时候，<strong>JS 自动转换了数据类型</strong></li>
</ul>
<hr>
</li>
<li><h3 id="转换为布尔型"><a href="#转换为布尔型" class="headerlink" title="转换为布尔型:"></a>转换为布尔型:</h3><table>
<thead>
<tr>
<th align="center">方式</th>
<th align="center">说明</th>
<th align="center">案例</th>
</tr>
</thead>
<tbody><tr>
<td align="center">Boolean()函数</td>
<td align="center">其他类型转成布尔值</td>
<td align="center">Boolean(‘true’);</td>
</tr>
</tbody></table>
<ul>
<li><strong>代表空、否定的值</strong>会被转换为 <code>false</code>  ，如 ‘’、0、NaN、null、undefined </li>
<li><strong>其余值都会被转换为 <code>true</code></strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="string">&#x27;&#x27;</span>)); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="number">0</span>)); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="literal">NaN</span>)); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="literal">null</span>)); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="literal">undefined</span>)); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="string">&#x27;小白&#x27;</span>)); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Boolean</span>(<span class="number">12</span>)); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>


</li>
</ul>
</li>
</ol>
<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">六根清静</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liugenqingjing2.coding.me/2020/09/06/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%89-ECMAScript%E4%B9%8B%E5%8F%98%E9%87%8F%E5%92%8C%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">https://liugenqingjing2.coding.me/2020/09/06/JavaScript知识点总结-三-ECMAScript之变量和数据类型/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liugenqingjing2.coding.me" target="_blank">小何blog (记录美好)</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%B3%BB%E5%88%97%F0%9F%8F%AC/">系列🏬</a><a class="post-meta__tags" href="/tags/JavaScript/">JavaScript</a><a class="post-meta__tags" href="/tags/ECMAScript/">ECMAScript</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-a049026224c43dcadeabad571c8d0d27_r.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" target="_blank"><img class="post-qr-code-img" data-lazy-src="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/09/08/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E5%9B%9B-ECMAScript%E4%B9%8B%E8%BF%90%E7%AE%97%E7%AC%A6%E5%92%8C%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6%E5%88%86%E6%94%AF%E7%BB%93%E6%9E%84/"><img class="prev-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-62a1837d21c646084077622c3d2115b0_r.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JavaScript知识点总结(四.ECMAScript之运算符和流程控制分支结构)</div></div></a></div><div class="next-post pull-right"><a href="/2020/09/05/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%BA%8C-JavaScript%E7%AE%80%E4%BB%8B/"><img class="next-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-fdfecf9ae52fea38652fdc86757173a6_r.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">JavaScript知识点总结(二.JavaScript简介)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/09/13/JavaScript知识点总结-七-JavaScript预解析和对象/" title="JavaScript知识点总结(七.JavaScript预解析和对象)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200913/WKp@vPE1Cm1Z.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-13</div><div class="title">JavaScript知识点总结(七.JavaScript预解析和对象)</div></div></a></div><div><a href="/2020/09/09/JavaScript知识点总结-五-ECMAScript之数组/" title="JavaScript知识点总结(五.ECMAScript之数组)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-fb37f4ec3f0e1eff232ec6e3b225f86a_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-09</div><div class="title">JavaScript知识点总结(五.ECMAScript之数组)</div></div></a></div><div><a href="/2020/09/10/JavaScript知识点总结-六-ECMAScrip之函数和作用域/" title="JavaScript知识点总结(六.ECMAScrip之函数和作用域)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-311744a9352d16d336652eb4577fa237_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-10</div><div class="title">JavaScript知识点总结(六.ECMAScrip之函数和作用域)</div></div></a></div><div><a href="/2020/09/08/JavaScript知识点总结-四-ECMAScript之运算符和流程控制分支结构/" title="JavaScript知识点总结(四.ECMAScript之运算符和流程控制分支结构)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-62a1837d21c646084077622c3d2115b0_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-08</div><div class="title">JavaScript知识点总结(四.ECMAScript之运算符和流程控制分支结构)</div></div></a></div><div><a href="/2020/09/14/JavaScript知识点总结-八-JavaScript-内置对象/" title="JavaScript知识点总结(八.JavaScript内置对象)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200914/it!NQ33FHCp7.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-14</div><div class="title">JavaScript知识点总结(八.JavaScript内置对象)</div></div></a></div><div><a href="/2020/09/17/JavaScript知识点总结-九-JavaScript的Web-APIs简介/" title="JavaScript知识点总结(九.JavaScript的Web APIs简介)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200917/7cKUzRmy@FxZ.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-17</div><div class="title">JavaScript知识点总结(九.JavaScript的Web APIs简介)</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">六根清静</div><div class="author-info__description">记录美好，记录生活，记录学习</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/he_chaoming/dashboard/projects?scope=public&amp;&amp;sort="><i class="fab fa-gofore"></i><span>My Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/he1213114428" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:484695754@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="tencent://message/?uin=484695754" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div></div><div class="card-widget card-recent-post"><div id="gamenews"><div class="card-content"><div class="item-headline"><i class="fas fa-cube"></i><span>ROLL资讯</span><i class="fas fa-retweet" @click="changetype(current)" style="float:right;margin-top:8px"></i></div><div class="newsbar"><span v-for="(type, index) in listtype" v-on:click="addClass(index)" v-bind:class="{ listtypeon:index==current}">{{type}}</span></div><div class="aside-list"><div class="aside-list-item" v-for="(news,index) in newsvue"><a class="thumbnail" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title"><img class="loaded" onerror="this.onerror=null;this.src='/img/404.jpg'" data-ll-status="loaded" :src="news.imgList[0]"/></a><div class="content"><a class="title" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title">{{news.title}}</a><time>{{news.postTime}}</time></div></div></div></div><div id="newsmodal"><button class="modalclose" @click="hidemodle()">关闭</button><h2>{{newpostvue.title}} </h2><h4>{{newpostvue.ptime}} &nbsp;&nbsp; {{newpostvue.source}}</h4><div v-html="newpostvue.content"></div></div></div></div><div class="card-widget card-shuo"><div class="card-content" style="height:auto;min-height:280px;"><div class="item-headline"><i class="fas fa-comments"></i><span>&#x8BF4;&#x8BF4</span><a id="shuovisualchange" style="cursor:pointer;float:right" onclick="shuovisualchange()">编辑</a></div><div id="artitalk_main" style="width:100%;height:100%;padding:10px"></div></div></div><div class="sticky_layout"></div><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-paw fa-spin"></i><span>那年今日</span></div><div id="history-news" style="height: 100px;overflow: hidden;"><div id="history-card"></div></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">大学生一枚，软件工程，想做全栈攻城狮，哈哈，有兴趣可以加 QQ:484695754 (也可以点上面的logo)，一起交流学习</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">变量：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E6%A6%82%E8%BF%B0%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">变量概述：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%8F%98%E9%87%8F"><span class="toc-number">1.1.1.</span> <span class="toc-text">什么是变量:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E5%82%A8"><span class="toc-number">1.1.2.</span> <span class="toc-text">变量在内存中的存储:</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">1.2.</span> <span class="toc-text">变量的使用:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A3%B0%E6%98%8E%E5%8F%98%E9%87%8F"><span class="toc-number">1.2.1.</span> <span class="toc-text">声明变量:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8"><span class="toc-number">1.2.1.1.</span> <span class="toc-text">注:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC"><span class="toc-number">1.2.2.</span> <span class="toc-text">赋值:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-1"><span class="toc-number">1.2.2.1.</span> <span class="toc-text">注:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">1.2.3.</span> <span class="toc-text">变量的初始化:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-2"><span class="toc-number">1.2.3.1.</span> <span class="toc-text">注:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E8%AF%AD%E6%B3%95%E6%89%A9%E5%B1%95"><span class="toc-number">1.3.</span> <span class="toc-text">变量语法扩展:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0%E5%8F%98%E9%87%8F"><span class="toc-number">1.3.1.</span> <span class="toc-text">更新变量:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%8C%E6%97%B6%E5%A3%B0%E6%98%8E%E5%A4%9A%E4%B8%AA%E5%8F%98%E9%87%8F"><span class="toc-number">1.3.2.</span> <span class="toc-text">同时声明多个变量:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A3%B0%E6%98%8E%E5%8F%98%E9%87%8F%E7%89%B9%E6%AE%8A%E6%83%85%E5%86%B5"><span class="toc-number">1.3.3.</span> <span class="toc-text">声明变量特殊情况:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-3"><span class="toc-number">1.3.3.1.</span> <span class="toc-text">注:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83"><span class="toc-number">1.4.</span> <span class="toc-text">变量命名规范:</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%AE%80%E4%BB%8B%EF%BC%9A"><span class="toc-number">2.1.</span> <span class="toc-text">数据类型简介：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%9A"><span class="toc-number">2.1.1.</span> <span class="toc-text">为什么需要数据类型：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%9A"><span class="toc-number">2.1.2.</span> <span class="toc-text">变量的数据类型：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%88%86%E7%B1%BB"><span class="toc-number">2.1.3.</span> <span class="toc-text">数据类型的分类:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#JS-%E6%8A%8A%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%88%86%E4%B8%BA%E4%B8%A4%E7%B1%BB"><span class="toc-number">2.1.3.1.</span> <span class="toc-text">JS 把数据类型分为两类:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E5%8D%95%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%9A"><span class="toc-number">2.2.</span> <span class="toc-text">简单数据类型：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%80%E5%8D%95%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%88%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%89"><span class="toc-number">2.2.1.</span> <span class="toc-text">简单数据类型（基本数据类型）:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9E%8B-Number%EF%BC%9A"><span class="toc-number">2.2.2.</span> <span class="toc-text">数字型 Number：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9E%8B%E8%BF%9B%E5%88%B6"><span class="toc-number">2.2.2.1.</span> <span class="toc-text">数字型进制:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9E%8B%E8%8C%83%E5%9B%B4"><span class="toc-number">2.2.2.2.</span> <span class="toc-text">数字型范围:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9E%8B%E4%B8%89%E4%B8%AA%E7%89%B9%E6%AE%8A%E5%80%BC"><span class="toc-number">2.2.2.3.</span> <span class="toc-text">数字型三个特殊值:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isNaN"><span class="toc-number">2.2.2.4.</span> <span class="toc-text">isNaN():</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%9E%8B-String"><span class="toc-number">2.2.3.</span> <span class="toc-text">字符串型 String:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%BC%95%E5%8F%B7%E5%B5%8C%E5%A5%97"><span class="toc-number">2.2.3.1.</span> <span class="toc-text">字符串引号嵌套:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E4%B9%89%E7%AC%A6"><span class="toc-number">2.2.3.2.</span> <span class="toc-text">字符串转义符:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6"><span class="toc-number">2.2.3.3.</span> <span class="toc-text">字符串长度:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%8B%BC%E6%8E%A5"><span class="toc-number">2.2.3.4.</span> <span class="toc-text">字符串拼接:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%8B%BC%E6%8E%A5%E5%8A%A0%E5%BC%BA"><span class="toc-number">2.2.3.5.</span> <span class="toc-text">字符串拼接加强:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%83%E5%B0%94%E5%9E%8B-Boolean"><span class="toc-number">2.2.4.</span> <span class="toc-text">布尔型 Boolean:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Undefined-%E5%92%8C-Null"><span class="toc-number">2.2.5.</span> <span class="toc-text">Undefined 和 Null:</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E5%8F%98%E9%87%8F%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.3.</span> <span class="toc-text">获取变量数据类型:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E6%A3%80%E6%B5%8B%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.3.1.</span> <span class="toc-text">获取检测变量的数据类型:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E9%9D%A2%E9%87%8F"><span class="toc-number">2.3.2.</span> <span class="toc-text">字面量:</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.4.</span> <span class="toc-text">数据类型转换:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.4.1.</span> <span class="toc-text">什么是数据类型转换:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">2.4.2.</span> <span class="toc-text">转换为字符串:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BD%AC%E6%8D%A2%E4%B8%BA%E6%95%B0%E5%AD%97%E5%9E%8B%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89"><span class="toc-number">2.4.3.</span> <span class="toc-text">转换为数字型（重点）:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%B8%83%E5%B0%94%E5%9E%8B"><span class="toc-number">2.4.4.</span> <span class="toc-text">转换为布尔型:</span></a></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210321/qWPEashJOuNK.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十三.跨域介绍和JSONP介绍)"/></a><div class="content"><a class="title" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)">Node.js学习(二十三.跨域介绍和JSONP介绍)</a><time datetime="2021-03-21T13:40:58.000Z" title="发表于 2021-03-21 21:40:58">2021-03-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/CvAoe6kC5*f2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十二.Node.js项目流程(下))"/></a><div class="content"><a class="title" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))">Node.js学习(二十二.Node.js项目流程(下))</a><time datetime="2021-03-20T14:33:29.000Z" title="发表于 2021-03-20 22:33:29">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/gSrAfCznw@^F.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十一.Node.js项目流程(中))"/></a><div class="content"><a class="title" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))">Node.js学习(二十一.Node.js项目流程(中))</a><time datetime="2021-03-15T04:35:12.000Z" title="发表于 2021-03-15 12:35:12">2021-03-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/UMp@B^akHmf8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十.Node.js项目流程(上))"/></a><div class="content"><a class="title" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))">Node.js学习(二十.Node.js项目流程(上))</a><time datetime="2021-03-14T14:36:58.000Z" title="发表于 2021-03-14 22:36:58">2021-03-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210227/EcgLTE4WPOp^.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(十九.封装操作数据库和CSRF)"/></a><div class="content"><a class="title" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)">Node.js学习(十九.封装操作数据库和CSRF)</a><time datetime="2021-02-27T13:20:18.000Z" title="发表于 2021-02-27 21:20:18">2021-02-27</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 六根清静</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi,  welcome  to  my  <a  href="">blog</a>!</div><div class="icp"><a><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>豫ICP备2020025430号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module" defer></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 50000);</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'kW2ft895T235y7DxmyJmXX5X-MdYXbMMI',
      appKey: 'v0zBPCAdwiJ0xg4s4eSfusLD',
      placeholder: '建议使用QQ邮箱，评论头像采用QQ头像',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: 'https://???????.api.lncldglobal.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      master: '1f76478c4ec918ffc6d50de6b68db531'.split(','),
      friends: '5c?????bfe6rfc72a????e268ad3819c,7c?????bfe65fc02a????e2????3919c'.split(','),
      tagMeta: '博主,小伙伴,访客'.split(',')
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src='https://cdn.jsdelivr.net/npm/artitalk'></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script src="/js/list.js"></script><script src="/js/gitcalendar.js"></script><script src="/js/calendar.js"></script><script src="/js/xkTool.js"></script><script src="/js/pjax.js"></script><script src="/magnet/js/vue.min.js"></script><script src="/magnet/js/catalogMagnet.js"></script><script src="/js/airvisualapi.js"></script><script src="/js/history.js"></script><script src="/js/historyroll.js"></script><script src="/js/change.js"></script><script type="text/javascript" src="https://www.airvisual.com/scripts/widget_v2.0.js"></script><script> setTimeout(function(){$('.monoline').eq(0).html($(".monoline strong").eq(0).text().replace('°','℃'));},5000);</script><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="/js/myBg.js"></script><script src="/js/shuo.js"></script><script src="/js/artitalkkey.js"></script><script src="/news/js/keys.js"></script><script src="/news/js/news.js"></script><script src="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/js/pool.min.js"><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/stars/stars.js"></script><script src="https://cdn1.lncld.net/static/js/3.5.0/av-min.js"></script><script src="/zan/zan.js"></script><div class="aplayer no-destroy" data-id="2916766519" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" muted></div><script src="/swiper/swiper.min.js"></script><script src="/swiper/swiperindex.js"></script><script async src="//at.alicdn.com/t/font_2264842_3izu8i5eoc2.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="/js/third-party/fireworks.js"></script><script src="/js/third-party/activate-power-mode.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6fdec148.js","daovoice")
</script><script>var isChatBtn = true
daovoice('init', {
  app_id: '6fdec148',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (true) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/unitychan.model.json"},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":true,"scale":0.6},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body></html>